package com.wjd.store;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

/**
 * 词语存储器
 *
 * @author weijiaduo
 * @since 2024/3/18
 */
public class WordStore extends RecordTree<WordRecord> {

    public WordStore(String baseDir) throws IOException {
        super(baseDir);
    }

    public WordStore(String baseDir, String ext) throws IOException {
        super(baseDir, ext);
    }

    @Override
    protected WordRecord readRecord(DataInputStream in) throws IOException {
        String word = in.readUTF();
        long pageId = in.readLong();
        int pv = in.readInt();
        double tf = in.readDouble();
        boolean isTitle = in.readBoolean();
        return new WordRecord(word, pageId, pv, tf, isTitle);
    }

    @Override
    protected void writeRecord(DataOutputStream out, WordRecord record) throws IOException {
        out.writeUTF(record.getWord());
        out.writeLong(record.getPageId());
        out.writeInt(record.getPageValue());
        out.writeDouble(record.getTf());
        out.writeBoolean(record.isTitled());
    }

}
